package cn.deschen.biz.service.impl;

import cn.deschen.biz.domain.entity.CmUser;
import cn.deschen.biz.mapper.CmUserMapper;
import cn.deschen.biz.service.CmUserService;
import cn.deschen.common.config.security.UserDetails;
import cn.deschen.common.config.security.UserDetailsService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * <p>
 * 后台用户 服务实现类
 * </p>
 *
 * @author deschen
 * @since 2021-06-02
 */
@Service
public class CmUserServiceImpl extends ServiceImpl<CmUserMapper, CmUser> implements CmUserService, UserDetailsService {

    @Override
    public UserDetails loadUserByUsername(String userName) {
        QueryWrapper<CmUser> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(CmUser::getUsername, userName);
        List<CmUser> userList = list(wrapper);
        if (CollectionUtils.isEmpty(userList)) {
            return null;
        }
        return userList.get(0);
    }
}
